package com.sharing.library.controller;

import com.sharing.library.entity.Book;
import com.sharing.library.entity.User;
import com.sharing.library.repository.UserRepository;
import com.sharing.library.repository.dto.BookCondition;
import com.sharing.library.repository.spec.BookSpec;
import com.zhx.framework.util.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhanghaixuan
 * @create 2018/4/24-下午8:10
 **/
@RestController
@RequestMapping("/user")
@Api(description="前端用户列表")
public class UserController {

    @Autowired
    private UserRepository userRepository;

    //获取列表
    //列表
    @PostMapping("/list")
    @ApiOperation(value="用户列表", notes="用户列表")
    public Result list (Pageable pageable){

        Page<User> all = userRepository.findAll(pageable);

        return Result.OK("",all);
    }

    //获取列表
    //列表
    @PostMapping("/detail")
    @ApiOperation(value="用户详情", notes="用户详情")
    public Result detail (@RequestParam Long id){

        User one = userRepository.findOne(id);

        return Result.OK("",one);
    }


    @PostMapping("/pwd")
    @ApiOperation(value="更新密码", notes="更新密码")
    public Result pwd(@RequestParam Long userId){
        User one = userRepository.findOne(userId);
        one.setPassword("123456");
        one = userRepository.save(one);
        return Result.OK("",one);
    }
}
